package com.dc.service.handler;

import com.alibaba.fastjson.JSON;
import com.dc.enums.ServiceIdType;
import com.dc.factory.DeviceFactory;
import com.dc.netty.TcpServer;
import com.dc.ro.CommonParams;
import com.dc.service.DeviceService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * xx设备命令发送
 */
@Service
@Slf4j
public class DeviceFireHandler implements DeviceService, InitializingBean {

    @Resource
    TcpServer tcpServer;

    @Override
    public void deviceHandler(String payLoad, String mqttId, CommonParams commonParams) {
        log.info("xx设备命令发送： {}", payLoad);
        //执行业务
        // TODO 收到mqtt消息,调用netty下发指令
        tcpServer.sendOutContent("", JSON.toJSONString(payLoad));
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        DeviceFactory.register(ServiceIdType.FIRE_SERVICE_ID.getType(), this);
    }
}
